package com.yj.transport.mapper;

import com.yj.transport.entity.TransportJournal;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by zhengguanyong on 2017/12/6.
 */

@Repository
@Mapper
public interface TransportJournalMapper {

    @Insert("INSERT INTO transport_journal " +
            "(`transport_info_id`, `transport_type`, `arrive_place`, `arrive_time`, `longitude`, `latitude`,`place_type`, `create_time`) " +
            "VALUES(#{item.transport_info_id}, #{item.transport_type}, #{item.arrive_place}, " +
            "#{item.arrive_time}, #{item.longitude}, #{item.latitude},#{item.place_type},now())")
    void createTransportJournal(@Param("item") TransportJournal item);

    @Select("select * from transport_journal where id=#{id} limit 1")
    TransportJournal getTransportJournalDetailById(@Param("id") Integer id);

    @Select("select * from transport_journal where transport_info_id=#{transport_info_id} order by arrive_time desc limit 1")
    TransportJournal getLastTransportJournalDetail(@Param("transport_info_id") Integer transport_info_id);

    @Select("select * from transport_journal where transport_info_id=#{transport_info_id} order by arrive_time")
    List<TransportJournal> getTransportJournalListByInfoId(@Param("transport_info_id") Integer transport_info_id);

    @Select("select * from transport_journal where transport_info_id=#{transport_info_id} order by arrive_time desc limit 1")
    TransportJournal getJournalDetailByPlace(@Param("transport_info_id") Integer transport_info_id,@Param("arrive_place") String arrive_place);
}

